﻿<KCtl:BaseUserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:KCtl="clr-namespace:Kiva7.Controls"
    xmlns:my="clr-namespace:Kiva7.Pages" x:Class="Kiva7.Pages.MainLenderControl" 
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    
    d:DesignHeight="800" d:DesignWidth="480" Loaded="BaseUserControlLoaded">

    <Grid>

        <ProgressBar Visibility="{Binding IsLoaded, Converter={StaticResource booleanToNotVisibility}}" 
                     IsIndeterminate="{Binding IsLoaded, Converter={StaticResource notBooleanConverter}}" 
                     Style="{StaticResource CustomIndeterminateProgressBar}"
                     VerticalAlignment="Stretch" />
        <Grid x:Name="grid" Visibility="Collapsed">
            <ScrollViewer Visibility="{Binding IsLoaded, Converter={StaticResource booleanToVisibility}}">
                <Grid Background="{StaticResource KivaBackgroundBrush}">

                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition  />
                        <RowDefinition  />
                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition MaxWidth="200" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>

                    <StackPanel x:Name="LayoutRoot" Grid.Column="1" Grid.Row="0"
                                Style="{StaticResource KivaDetailStyle}">


                        <TextBlock x:Name="LenderID" Text="{Binding UID}" Visibility="Collapsed" />

                        <TextBlock Text="{Binding L.Name, Source={StaticResource L}}"  
                               Style="{StaticResource KivaTextNormalStyle}"
                               Visibility="{Binding Name, Converter={StaticResource stringVisibility}}" />
                        <TextBlock Text="{Binding Name}" 
                               Style="{StaticResource KivaTextAccentStyle}"
                               TextWrapping="Wrap" />

                        <TextBlock Text="{Binding L.MemberSince, Source={StaticResource L}}"  Style="{StaticResource KivaTextNormalStyle}"/>
                        <TextBlock Text="{Binding MemberSince, Converter={StaticResource toShortDate}}" 
                           Style="{StaticResource KivaTextAccentStyle}"
                       Visibility="{Binding MemberSince, Converter={StaticResource dateTimeVisibility}}"
                           TextWrapping="Wrap"/>
                        <TextBlock Text="{Binding L.WhereAbouts, Source={StaticResource L}}"  Style="{StaticResource KivaTextNormalStyle}"
                       Visibility="{Binding WhereAbouts, Converter={StaticResource stringVisibility}}" />
                        <TextBlock Text="{Binding WhereAbouts}" 
                           Visibility="{Binding WhereAbouts, Converter={StaticResource stringVisibility}}"
                           Style="{StaticResource KivaTextAccentStyle}"
                           TextWrapping="Wrap"/>

                        <TextBlock Text="{Binding L.Occupation, Source={StaticResource L}}"  Style="{StaticResource KivaTextNormalStyle}"
                       Visibility="{Binding Occupation, Converter={StaticResource stringVisibility}}" />
                        <TextBlock Text="{Binding Occupation}" 
                           Visibility="{Binding Occupation, Converter={StaticResource stringVisibility}}"
                           Style="{StaticResource KivaTextAccentStyle}"
                           TextWrapping="Wrap"
                       />
                    </StackPanel>
                    <StackPanel Grid.Column="0" Grid.Row="0">
                        <Button Click="ShowLenderPageClick" BorderThickness="0" Margin="0,0,0,0" Padding="0,0,0,0"
                        Visibility="{Binding Image, Converter={StaticResource objectVisibility}}">
                            <KCtl:KivaImageControl x:Name="imgLender"
                                                   ImageData="{Binding Image}" 
                                                   ImageSize="FullSize"
                                    Width="210" Height="210" Margin="0,0,0,0" Padding="0,0,0,0"
                                    HorizontalAlignment="Right" VerticalAlignment="Top"/>
                        </Button>
                    </StackPanel>

                    <StackPanel Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2">
                        <Button Click="ViewLoansClick"
                             Visibility="{Binding LoanCount, Converter={StaticResource numberVisibility}}"
                                Style="{StaticResource KivaButtonStyle}">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding L.YouHaveLoans, Source={StaticResource L}}"  Style="{StaticResource KivaButtonTextStyle}"/>
                                <TextBlock Text="{Binding LoanCount}" Style="{StaticResource KivaButtonTextStyle}"/>
                                <TextBlock Text="{Binding L.Loans, Source={StaticResource L}}"  Style="{StaticResource KivaButtonTextStyle}"/>
                            </StackPanel>
                        </Button>

                        <my:NoLoansControl x:Name="noLoansControl1" 
                                     Visibility="{Binding LoanCount, Converter={StaticResource numberNotVisibility}}"/>
                        
                        <Grid Style="{StaticResource KivaDetailStyle}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="78"/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>

                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>

                            <TextBlock Text="{Binding L.Fundraising, Source={StaticResource L}}" Style="{StaticResource KivaTextNormalStyle}"
                                   Grid.Column="1" Grid.Row="0"
                                   Visibility="{Binding Loans.FundraisingCount, Converter={StaticResource numberVisibility}}"/>
                            <TextBlock Text="{Binding Loans.FundraisingCount}" Style="{StaticResource KivaTextAccentStyle}"
                                   Grid.Column="0" Grid.Row="0" TextAlignment="Right"
                                   Visibility="{Binding Loans.FundraisingCount, Converter={StaticResource numberVisibility}}"/>

                            <TextBlock Text="{Binding L.Funded, Source={StaticResource L}}" Style="{StaticResource KivaTextNormalStyle}"
                                   Grid.Column="1" Grid.Row="1"
                                   Visibility="{Binding Loans.FundedCount, Converter={StaticResource numberVisibility}}"/>
                            <TextBlock Text="{Binding Loans.FundedCount}" Style="{StaticResource KivaTextAccentStyle}"
                                   Grid.Column="0" Grid.Row="1" TextAlignment="Right"
                                   Visibility="{Binding Loans.FundedCount, Converter={StaticResource numberVisibility}}"/>

                            <TextBlock Text="{Binding Loans.InRepaymentCount}" Style="{StaticResource KivaTextAccentStyle}"
                                   TextAlignment="Right" Grid.Column="0" Grid.Row="2"
                                   Visibility="{Binding Loans.InRepaymentCount, Converter={StaticResource numberVisibility}}"/>
                            <toolkit:WrapPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2">
                                <TextBlock Text="{Binding L.PayingBackOfWhich, Source={StaticResource L}}" Style="{StaticResource KivaTextNormalStyle}"
                                   Visibility="{Binding Loans.InRepaymentCount, Converter={StaticResource numberVisibility}}"/>
                                <TextBlock Text="{Binding Loans.RepaidPercentage, Converter={StaticResource toPercentage}}" 
                                   Style="{StaticResource KivaTextAccentStyle}"
                                   Visibility="{Binding Loans.InRepaymentCount, Converter={StaticResource numberVisibility}}"
                                   TextAlignment="Right"/>
                                <TextBlock Text="{Binding L.Repaid, Source={StaticResource L}}" Style="{StaticResource KivaTextNormalStyle}"
                                   Visibility="{Binding Loans.InRepaymentCount, Converter={StaticResource numberVisibility}}"/>
                            </toolkit:WrapPanel>


                            <TextBlock Text="{Binding L.PaidBack, Source={StaticResource L}}" Style="{StaticResource KivaTextNormalStyle}"
                                   Grid.Column="1" Grid.Row="3"
                                   Visibility="{Binding Loans.PaidCount, Converter={StaticResource numberVisibility}}"/>
                            <TextBlock Text="{Binding Loans.PaidCount}" Style="{StaticResource KivaTextAccentStyle}"
                                   Grid.Column="0" Grid.Row="3" TextAlignment="Right"
                                   Visibility="{Binding Loans.PaidCount, Converter={StaticResource numberVisibility}}"/>



                            <TextBlock Text="{Binding L.Refunded, Source={StaticResource L}}" Style="{StaticResource KivaTextNormalStyle}"
                                   Grid.Column="1" Grid.Row="4"
                                   Visibility="{Binding Loans.RefundedCount, Converter={StaticResource numberVisibility}}"/>
                            <TextBlock Text="{Binding Loans.RefundedCount}" Style="{StaticResource KivaTextAccentStyle}"
                                   Grid.Column="0" Grid.Row="4" TextAlignment="Right"
                                   Visibility="{Binding Loans.RefundedCount, Converter={StaticResource numberVisibility}}"/>


                            <TextBlock Text="{Binding L.Defaulted, Source={StaticResource L}}" Style="{StaticResource KivaTextNormalStyle}"
                                   Grid.Column="1" Grid.Row="5"
                                   Visibility="{Binding Loans.DefaultedCount, Converter={StaticResource numberVisibility}}"/>
                            <TextBlock Text="{Binding Loans.DefaultedCount}" Style="{StaticResource KivaTextAccentStyle}"
                                   Grid.Column="0" Grid.Row="5" TextAlignment="Right"
                                   Visibility="{Binding Loans.DefaultedCount, Converter={StaticResource numberVisibility}}"/>


                            <TextBlock Text="{Binding L.Expired, Source={StaticResource L}}" Style="{StaticResource KivaTextNormalStyle}"
                                   Grid.Column="1" Grid.Row="6"
                                   Visibility="{Binding Loans.ExpiredCount, Converter={StaticResource numberVisibility}}"/>
                            <TextBlock Text="{Binding Loans.ExpiredCount}" Style="{StaticResource KivaTextAccentStyle}"
                                   Grid.Column="0" Grid.Row="6" TextAlignment="Right"
                                   Visibility="{Binding Loans.ExpiredCount, Converter={StaticResource numberVisibility}}"/>


                            <TextBlock Text="{Binding L.SuccesfullInvitees, Source={StaticResource L}}"  
                                   Style="{StaticResource KivaTextNormalStyle}"
                                   Grid.Column="1" Grid.Row="7"
                                   Visibility="{Binding InviteeCount, Converter={StaticResource numberVisibility}}"/>
                            <TextBlock Text="{Binding InviteeCount}" 
                                   Style="{StaticResource KivaTextAccentStyle}"
                                   Grid.Column="0" Grid.Row="7" TextAlignment="Right"
                                   Visibility="{Binding InviteeCount, Converter={StaticResource numberVisibility}}"/>

                        </Grid>


                    </StackPanel>

                </Grid>
            </ScrollViewer>
        </Grid>
    </Grid>
</KCtl:BaseUserControl>
